<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // -计算数组中每个元素在数组中出现的次数[1, 2, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3];并输出
        //item === 1 &&one++   短路操作
        //item === 1?one++:''  三元表达式
        function fn(a){
           
        var one=0;
        two=0;
        three=0;
        four=0;
        five=0;
        six=0;
        seven=0;
        for(var i=0;i<a.length;i++){
            a[i]===1&&one++;
            a[i]===2&&two++;
            a[i]===3&&three++;
            a[i]===4&&four++;
            a[i]===5?five++:'';
            a[i]===6?six++:'';
            a[i]===7?seven++:'';
        }
        return [one,two,three,four,five,six,seven]
        }
       console.log(fn([1, 2, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3]))
        
       
    </script>
</body>
</html>